package com.lovo.addressbook;

import java.io.File;

import junit.framework.Assert;

public class TestUtil {
	
	public static void assertMatch(User user1, User user2)
	{
		Assert.assertEquals(user1.getImagePath(), user2.getImagePath());
		Assert.assertEquals(user1.getName(),user2.getName());
		Assert.assertEquals(user1.getNo(), user2.getNo());
		Assert.assertEquals(user1.getPhone(), user2.getPhone());
		Assert.assertEquals(user1.getSex(), user2.getSex());
		Assert.assertEquals(user1.getAge(), user2.getAge());

	}
	public static void assertMatch(MainWindow mw, User user)
	{
		boolean sexright = false;
		if (mw.rBtnFemale.isSelected()) {
			if (user.getSex().equals("F"))
				sexright = true;
		}
		else {
			if (user.getSex().equals("M"))
				sexright = true;
		}
		Assert.assertEquals(true, sexright);
		Assert.assertEquals(true, mw.txtAge.getText().equals(user.getAge().toString()));
		Assert.assertEquals(true, mw.txtAge.getText().equals(user.getAge().toString()));
		Assert.assertEquals(true, mw.txtName.getText().equals(user.getName()));
		Assert.assertEquals(true, mw.txtNum.getText().equals(user.getNo()));
		Assert.assertEquals(true, mw.txtPhotoAddr.getText().equals(user.getImagePath()));
		Assert.assertEquals(true, mw.txtTel.getText().equals(user.getPhone()));
	}
	
	public static User[] getUsers()
	{
		User [] users = new User[4];
		for (int i = 0; i != 4; ++i) {
			users[i] = new User();
		}
		users[1].setAge(10);
		users[1].setImagePath("1.jpg");
		users[1].setName("shu");
		users[1].setNo("1");
		users[1].setPhone("123");
		users[1].setSex("M");
		
		users[2].setAge(11);
		users[2].setImagePath("2.jpg");
		users[2].setName("duan");
		users[2].setNo("2");
		users[2].setPhone("321");
		users[2].setSex("M");
		
		users[3].setAge(12);
		users[3].setImagePath("3.jpg");
		users[3].setName("song");
		users[3].setNo("3");
		users[3].setPhone("213");
		users[3].setSex("M");
		
		users[0].setAge(10);
		users[0].setImagePath("0.jpg");
		users[0].setName("yang");
		users[0].setNo("4");
		users[0].setPhone("312");
		users[0].setSex("F");
		return users;
	}
	public static User getUser()
	{
		User user = new User();
		user.setAge(50);
		user.setImagePath("5.jpg");
		user.setName("hu");
		user.setNo("5");
		user.setPhone("132");
		user.setSex("M");
		return user;
		
	}
	public static void initialConfig()
	{
		File file = new File("config/telephone.dat");
		file.delete();
		PropertiesUtil pu = new PropertiesUtil("config/telephone.dat");
		User [] users = TestUtil.getUsers();
		for(int i = 0; i != users.length; ++i)
		{
			pu.save(users[i]);
		}
	}
	public static void main(String[] args)
	{
		File file = new File("config/telephone.dat");
		file.delete();
		PropertiesUtil pu = new PropertiesUtil("config/telephone.dat");
		User [] users = TestUtil.getUsers();
		for(int i = 0; i != users.length; ++i)
		{
			pu.save(users[i]);
		}
	}
}
